import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class LuasSegitiga{

	private	JFrame		aFrame = new JFrame("Luas Segitiga by kelompok 1");
		
	private	JPanel 		panel1 = new JPanel(),
						panel2 = new JPanel();
					
	private	JTextField	txtAlas = new JTextField(),
						txtTinggi = new JTextField();
					
	private	JLabel		lblAlas = new JLabel("Alas :"),
						lblTinggi = new JLabel("Tinggi :"),
						lblHasil = new JLabel("Hasil : "),
						lblBackground = new JLabel(new ImageIcon("bg.png"));
					
	private	JButton		btnClear = new JButton("Clear"),
						btnHasil = new JButton("Hasil"),
						btnClose = new JButton("Tutup");
	
	
	//function
	double Luas(double a, double t){
	
		return (a*t)/2;
		
	}
	
	//procedure untuk button clear
	void Clear(){
	
		txtAlas.setText("0");
		txtTinggi.setText("0");
		lblHasil.setText("Hasil : ");
	
	}
	
	public LuasSegitiga(){

		Clear();
		
		ActionListener alHasil = new	ActionListener(){
											public void actionPerformed(ActionEvent e){
												double alas = Double.parseDouble(txtAlas.getText());
												double tinggi = Double.parseDouble(txtTinggi.getText());		
												double luasSegitiga = Luas(alas,tinggi);
												lblHasil.setText("Hasil : "+luasSegitiga);
											}
										};
										
		ActionListener alClear = new	ActionListener(){
											public void actionPerformed(ActionEvent e){
												Clear();
											}
										};
										
		ActionListener alClose = new	ActionListener(){
											public void actionPerformed(ActionEvent e){
												System.exit(0);
											}
										};
										
		btnHasil.addActionListener(alHasil);
		btnClear.addActionListener(alClear);
		btnClose.addActionListener(alClose);
										
		panel1.setLayout(null);
		
		
		lblAlas.setBounds(20,20,80,20);
		lblTinggi.setBounds(20,60,80,20);
		lblHasil.setBounds(60,100,200,20);
		lblBackground.setBounds(0,0,500,375);
		txtAlas.setBounds(120,20,80,20);
		txtTinggi.setBounds(120,60,80,20);
		
		lblHasil.setOpaque(true);
		lblHasil.setFont(new Font("Arial",Font.BOLD,12));
		lblHasil.setBackground(Color.yellow);
		lblHasil.setForeground(Color.red);
		
		panel1.setLayout(null);
		

		panel1.add(lblAlas);
		panel1.add(lblTinggi);
		panel1.add(lblHasil);
		panel1.add(txtAlas);
		panel1.add(txtTinggi);
		panel1.add(lblBackground);
		
		panel2.setLayout(new FlowLayout(FlowLayout.CENTER));
		
		btnHasil.setMnemonic('H');
		btnClear.setMnemonic('C');
		btnClose.setMnemonic('T');
		
		panel2.add(btnHasil);
		panel2.add(btnClear);
		panel2.add(btnClose);
		
		aFrame.getContentPane().add(panel1, BorderLayout.CENTER);
		aFrame.getContentPane().add(panel2, BorderLayout.SOUTH);
		
		aFrame.setSize(500,400);
		aFrame.setVisible(true);
		aFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		aFrame.setLocation(300,150);
		
	}
	
	public static void main(String[] args){
	
		new LuasSegitiga();
		
	}
	
}